package com.li.list;

import java.util.Stack;

/**  
* 类说明   
*  
* @author ****  
* @date 2018年4月10日  新建  
*/
public class LList {
	Node head = null;
	
	public LList(){
		head = new Node();
	}
	static class Node{
		Node next;
		int key;
		
		public Node(int key){
			this.key = key;
		}
		
		public Node(){
			
		}
	}
	
	public static void main(String[] args) {
		Node node1 = new Node(1);
		Node node2 = new Node(2);
		Node node3 = new Node(3);
		Node node4 = new Node(4);
		Node node5 = new Node(5);
		Node node6 = new Node(6);
		
		LList list = new LList();
		Node head  = list.head;
		head.next = node1;
		node1.next = node2;
		node2.next = node3;
		node3.next = node4;
		node4.next = node5;
		node5.next = node6;
		
		rList3(head);
		print(head);
		System.out.println();
		//rPrint(head);
	}
	
	public static void print(Node head){
		if(head ==null){
			return;
		}
		Node node = head.next;
		while(node!=null){
			System.out.print(node.key+" ");
			node = node.next;
		}
	}
	
	public static void rPrint(Node head){
		if(head == null){
			return;
		}
		Stack<Node> s = new Stack<Node>();
		Node node = head.next;
		while(node!=null){
			s.push(node);
			node = node.next;
		}
		while(!s.isEmpty()){
			node = s.pop();
			System.out.print(node.key+" ");
		}
	}
	
	public static void RList(Node head){
		if(head == null){
			return;
		}
		Node pre = null;
		Node current = head.next;
		Node next = null;
		
		while(current!=null){
			next = current.next;
			
			current.next = pre;
			pre = current;
			current = next;
		}
		head.next = pre;
	}
	
	public static void rList2(Node head){
		if(head == null){
			return;
		}
		
		Node node = head.next;
		Node next = head;
		Stack<Node> s = new Stack<Node>();
		while(node!=null){
			s.push(node);
			node = node.next;
		}
		
		node = head;
		while(!s.isEmpty()){
			next = s.pop();
			node.next = next;
			node = next;
		}
		node.next = null;
	}
	
	public static void rList3(Node head){
		if(head == null){
			return;
		}
		
		Node node = head.next;
		head.next = null;
		Node next1 =null;
		Node next2 = null;
		while(node!=null){
			next1 = node.next;
			next2 =  head.next;
			head.next = node;
			node.next = next2;
			
			node = next1;
		}
	}
}
  